<template>
  <a-card :bordered="false">
    <super-query :fieldList="tableObj.columns" @ok="handleSuperQuery"/>
    <v-table
      ref="table"
      :data="loadData"
      :columns="tableObj.columns"
    >
      <span slot="action" slot-scope="{ row,text }">
        <span v-if='row.statusCode == 0'>
          <a href="javascript:;" @click='release(row)'>开始</a>
          <a-divider type="vertical" />
        </span>
        <span v-if='row.statusCode == 10'>
          <a href="javascript:;" @click='close(row)'>关闭</a>
          <a-divider type="vertical" />
        </span>
        <span v-if='row.statusCode == 10 && row.mode === "output"'>
          <a href="javascript:;" @click='work(row)'>报工</a>

        </span>
        <span v-else-if='row.statusCode == 10 && row.mode === "input"'>
          <a href="javascript:;" @click='devote(row)'>投料</a>
        </span>
      </span>
    </v-table>
    <devote-materail @ok='queryPage' ref='devoteMaterail'></devote-materail>
  </a-card>
</template>

<script>
import { fetchList, release, close } from '@/api/plan/workcenterplan'
import { TableMixin } from '@/mixins/TableMixin'
import { statusTypeList } from '@/dict'
import SuperQuery from '@comp/SuperQuery/SuperQuery'
import { tableObj } from './template'
import devoteMaterail from './devoteMaterail'
export default {
  name: 'WorkCenterPlan',
  mixins: [TableMixin],
  components: {
    SuperQuery,
    devoteMaterail
  },
  data () {
    return {
      tableObj,
      statusTypeList,
      dataSource: [],
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    work(row){
      this.$router.push({
        name: 'workPlatform',
        query: {
          workCenterPlanCode: row.workCenterPlanCode
        }
      })
    },
    // edit (record) {
    //   this.$refs.userAddOrUpdate.init(record.id, 'edit')
    // },

    devote(row){
      this.$refs.devoteMaterail.init(row.planCode,row.workCenterPlanCode)
    },
    release(row){
      release(row.workCenterPlanCode).then(res => {
        this.queryPage()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    close(row){
      close(row.workCenterPlanCode).then(res => {
        this.queryPage()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    handleSuperQuery (params) {
      if(params){
        this.queryParam.queryType = params.queryType
        this.queryParam.queryItems = encodeURI(JSON.stringify(params.queryItems))
      }else{
        this.queryParam.queryType = ''
        this.queryParam.queryItems = ''
      }
      this.queryPage()
    }
  }
}
</script>

<style scoped>

</style>
